package com.yvtian.pm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yvtian.pm.pojo.PmProjectEntity;
import com.yvtian.pm.dao.PmProjectMapper;
import com.yvtian.pm.service.PmProjectService;
import com.yvtian.pu.pojo.PuApplyForEntity;
import com.yvtian.utils.StringHelper;
import org.springframework.stereotype.Service;

/**
 * (pm_project)表服务实现类
 *
 * @author long
 * @since 2024-06-25 15:27:37
 */
@Service("pmProjectService")
public class PmProjectServiceImpl extends ServiceImpl<PmProjectMapper, PmProjectEntity> implements PmProjectService {

    @Override
    public IPage<PmProjectEntity> findByPage(Page<PmProjectEntity> page, PmProjectEntity pmProjectEntity) {
        LambdaQueryWrapper<PmProjectEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmProjectEntity::getIsDel, 0);
        getQueryWrapper(pmProjectEntity, queryWrapper);
        return this.page(page, queryWrapper);
    }

    private void getQueryWrapper(PmProjectEntity pmProjectEntity, LambdaQueryWrapper<PmProjectEntity> queryWrapper) {
        if (StringHelper.isNotEmpty(pmProjectEntity.getCode())){
            queryWrapper.like(PmProjectEntity::getCode, pmProjectEntity.getCode());
        }
        if (StringHelper.isNotEmpty(pmProjectEntity.getName())){
            queryWrapper.like(PmProjectEntity::getName, pmProjectEntity.getName());
        }
        if (StringHelper.isNotEmpty(pmProjectEntity.getContractCode())){
            queryWrapper.like(PmProjectEntity::getContractCode, pmProjectEntity.getContractCode());
        }
        if (ObjectUtils.isNotEmpty(pmProjectEntity.getAmount())){
            queryWrapper.eq(PmProjectEntity::getAmount, pmProjectEntity.getAmount());
        }
        if (ObjectUtils.isNotEmpty(pmProjectEntity.getBudget())){
            queryWrapper.eq(PmProjectEntity::getBudget, pmProjectEntity.getBudget());
        }
        if (StringHelper.isNotEmpty(pmProjectEntity.getCuName())){
            queryWrapper.like(PmProjectEntity::getCuName, pmProjectEntity.getCuName());
        }
        if (StringHelper.isNotEmpty(pmProjectEntity.getCuCode())){
            queryWrapper.like(PmProjectEntity::getCuCode, pmProjectEntity.getCuCode());
        }
        if (StringHelper.isNotEmpty(pmProjectEntity.getProjectStatus())){
            queryWrapper.eq(PmProjectEntity::getProjectStatus, pmProjectEntity.getProjectStatus());
        }
        if (!org.springframework.util.ObjectUtils.isEmpty(pmProjectEntity.getStatus())) {
            queryWrapper.eq(PmProjectEntity::getStatus, pmProjectEntity.getStatus());
        }
        if (StringHelper.isNotEmpty(pmProjectEntity.getCreateName())) {
            queryWrapper.like(PmProjectEntity::getCreateName, pmProjectEntity.getCreateName());
        }
        if (StringHelper.isNotEmpty(pmProjectEntity.getUpdateName())) {
            queryWrapper.like(PmProjectEntity::getUpdateName, pmProjectEntity.getUpdateName());
        }
        if (StringHelper.isNotEmpty(pmProjectEntity.getCreateUser())) {
            queryWrapper.like(PmProjectEntity::getCreateUser, pmProjectEntity.getCreateUser());
        }
        if (StringHelper.isNotEmpty(pmProjectEntity.getRemarks())) {
            queryWrapper.like(PmProjectEntity::getRemarks, pmProjectEntity.getRemarks());
        }
        if (StringHelper.isNotEmpty(pmProjectEntity.getCheckName())) {
            queryWrapper.like(PmProjectEntity::getCheckName, pmProjectEntity.getCheckName());
        }
        if (StringHelper.isNotEmpty(pmProjectEntity.getCheckUser())) {
            queryWrapper.like(PmProjectEntity::getCheckUser, pmProjectEntity.getCheckUser());
        }
    }
}

